package com.jackaltsc.mydemocustomview.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TextView;

import com.jackaltsc.mydemocustomview.R;
import com.jackaltsc.mydemocustomview.myview.MyFlowView;

/**
 * Created by JackalTsc on 2016/7/22.
 */
public class FlowActivity extends Activity {

    //自定义View
    private MyFlowView mvTest;
    //数据
    private String[] mData = new String[]{"爱心商品", "算法导论", "大米", "土豆", "衣服", "c语言程序设计",
            "爱心商品", "算法导论", "大米", "土豆", "衣服", "c语言程序设计",
            "爱心商品", "算法导论", "大米", "土豆", "衣服", "c语言程序设计"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flow);
        initView();
        initData();

    }

    private void initView() {

        //控件查找
        mvTest = (MyFlowView) findViewById(R.id.mfv_test);

    }

    public void initData() {

        LayoutInflater mInflater = LayoutInflater.from(this);

        for (int i = 0; i < mData.length; i++) {
            //这里是获得单个子View的布局
            TextView tv = (TextView) mInflater.inflate(R.layout.view_mfv_tv, mvTest, false);
            tv.setText(mData[i]);
            //添加到ViewGroup中
            mvTest.addView(tv);
        }
    }
}

